#ifndef THREAD_POOL_H
#define THREAD_POOL_H

#include <functional>
#include <vector>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <thread>
#include <iostream>
#include "mysql_connection_pool.h"  // 确保包含 MySQLConnectionPool 的头文件

class ThreadPool {
public:
    ThreadPool(size_t threads, MySQLConnectionPool& conn_pool);
    ~ThreadPool();

    template<class F>
    void enqueue(F&& f) {
        {
            std::lock_guard<std::mutex> lock(queue_mutex);
            tasks.emplace(std::forward<F>(f));
        }
        condition.notify_one();
    }

private:
    std::vector<std::thread> workers;
    std::queue<std::function<void()>> tasks;
    std::mutex queue_mutex;
    std::condition_variable condition;
    bool stop;
    MySQLConnectionPool& conn_pool;  // 添加成员变量
};

#endif // THREAD_POOL_H